<template>
	<view>
		<view class="main">

			<view class="i">
				<i class="iconfont icon-chenggong"></i>
			</view>
			<view class="t">发布成功</view>

			<view class="footer">
				<view class="a"  v-if="wid" @click="goView(wid)">进入该留言</view>
				<view class="a" @click="backIndex">返回首页</view>
			</view>

		</view>
		<view v-if="wid">
			<u-gap height="10" bg-color="#f8f8f8"></u-gap>
			<view class="rssbox">
				<view class="rss">
					<view class="rssdesc">
						<view class="rssdesc-title">
							订阅消息
						</view>
						<view class="rssdesc-desc">
							留言被处理后将会通过微信通知你
						</view>
					</view>
					<view :class="['rssbtn',rssStatus?'ok':'defn']" @click="rss">
						<i class="iconfont icon-xiaoxi" />{{rssTips}}
					</view>
				</view>
			</view>
		</view>
		<u-gap height="10" bg-color="#f8f8f8"></u-gap>

		<view class="more">
			<h3>看看更多</h3>
			<Lylist></Lylist>
		</view>

	</view>
</template>

<script>
	import Lylist from '@/uni_modules/Lylist/Lylist.vue';
	import {
		doWechatpush
	} from '@/api/api.js';
	export default {
		components: {
			Lylist
		},
		data() {
			return {
				rssTips: '点击订阅',
				rssStatus: false,
				wid: 0,
			}
		},
		onLoad(options) {
			this.wid = options.wid
		},

		methods: {
			goView(wid){
				uni.redirectTo({
					url:'/pages/index/thread?wid='+wid
				})
			},
			rss() {
				let _this = this
				wx.requestSubscribeMessage({
					tmplIds: ['gvzBY_YkmP0FLUJOAFz3JQpO4suI3tLHvpmee1bDaC4'],
					complete(res) {
						if (res.errMsg == "requestSubscribeMessage:ok") {
							if (res['gvzBY_YkmP0FLUJOAFz3JQpO4suI3tLHvpmee1bDaC4'] == 'accept') {
								doWechatpush({
									wid: _this.wid
								}).then(r => {
									if (r.data.code == 200) {
										_this.rssTips = '已订阅'
										_this.rssStatus = true
									}
								})
								// _this.rssTips = '已订阅'
								// _this.rssStatus = true
							}else if(res['gvzBY_YkmP0FLUJOAFz3JQpO4suI3tLHvpmee1bDaC4']=='reject'){
								uni.showModal({
									content:"你拒绝了订阅，你可以在该小程序设置中“接受通知”里重新开启后再点击该按钮",
									cancelText:"查看教程",
									confirmText:"我知道了"
								})
							}
						}
					}
				})
			},
			backIndex() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},

		},
	}
</script>

<style lang="scss" scoped>
	.rssbox {
		padding: 25rpx;
		border-radius: 15rpx;
		margin: 20rpx;
		position: relative;

		.rssbtn {
			background-color: $base-color;
			color: #fff;
			width: 180rpx;
			height: 60rpx;
			line-height: 60rpx;
			justify-content: center;
			font-size: 28rpx;
			display: flex;
			align-items: center;
			border-radius: 10rpx;

			&.ok {
				background-color: #eee;
				color: #999;

				.iconfont {
					color: #999;
				}

			}

			.iconfont {
				font-size: 32rpx;
				margin-right: 6rpx;
				color: #fff;
			}
		}
	}

	.rss {
		display: flex;
		width: 100%;
		justify-content: space-between;
		align-items: center;

		.rssdesc {
			text-align: left;
			width: calc(100% - 200rpx);

			.rssdesc-title {
				font-size: 32rpx;
				font-weight: bold;
				color: #444;
			}

			.rssdesc-desc {
				margin-top: 6rpx;
				font-size: 28rpx;
				color: #999;
			}
		}
	}

	.main {

		padding-top: 20rpx;
		text-align: center;


		.i {
			padding: 100rpx;
			padding-bottom: 0 !important;

			.iconfont {
				color: rgb(82, 196, 26);
				font-size: 200rpx;
			}
		}

		.t {
			margin-top: 30rpx;
			font-size: 36rpx;
		}

		.footer {
			margin-top: 120rpx;
			display: flex;
			padding: 60rpx 100rpx;
			justify-content: space-between;

			.a {
				color: #369;
				font-size: 28rpx;
			}
		}


	}

	.more {
		padding: 40rpx;
		background-color: #fff;
		text-align: left;

		h3 {
			font-size: 36rpx;
			padding: 0 10rpx;
			font-weight: bold;
			margin-bottom: 10rpx;
		}
	}
</style>